<include file="public@header"/>

<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li class="active"><a href="{:url('Message/index')}">我的消息列表</a></li>
    </ul>

    <form class="js-ajax-form" action="" method="post">
        <table class="table table-hover table-bordered table-list">
            <thead>
            <tr>
                <th>编号</th>
                <th>发送者</th>
                <th>主题</th>
                <th>发送时间</th>
            </tr>
            </thead>
            <notempty name="messages">
                <foreach name="messages" item="vo">
                    <if condition="$vo.msg_status eq 1">
                        <tr>
                    <else/>
                        <tr style="font-weight: bold;">
                    </if>
                        <td>{$vo.id}</td>
                        <td>{$vo.user_name}</td>
                        <td>
                            <a href="{:url('educational/Message/infoDetail',['msg_id'=>$vo.id])}" title="查看详情">
                                {$vo.subject}
                            </a>

                            <!--<if condition="$vo.msg_status eq 0">-->
                            <!--<span class='msg_status'>-->
                            <!--<a style="text-decoration: none;">-->
                                <!--<i class="fa fa-envelope-o fa-fw"></i>-->
                                <!--......-->
                            <!--</a>-->
                            <!--</span>-->
                                <!--<else/>-->
                                <!--<span><i class="fa fa-envelope-open-o fa-fw"></i>{$vo.content}</span>-->
                            <!--</if>-->
                        </td>
                        <td>{:date('Y-m-d H:i:s',$vo.create_time)}</td>
                    </tr>
                </foreach>
            </notempty>
        </table>
        <div class="pagination">{$page|default=''}</div>
    </form>
</div>

<script src="__STATIC__/js/admin.js"></script>
<script type="text/javascript">

    $('body').on('click', '.msg_status', function () {
        var $this = $(this);
        var msgId = $this.parents('tr').find('td:first').text();
        //ajax更改状态+获取内容
        $.ajax({
            url: "{:url('Message/ajaxRead')}",
            type: 'post',
            dataType: 'json',
            data: {"msg_id": msgId},
            success: function (jsonData) {
                var html = '<i class="fa fa-envelope-open-o fa-fw"></i>';
                if (jsonData.code == 1) {
                    $this.removeClass('msg_status');
                    html += jsonData.data;
                }
                $this.html(html);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                console.log('xhr=' + XMLHttpRequest.readyState + ' status=' + textStatus + ' error=' + errorThrown);
            }
        });

        var total = $(window.parent.document).find("#msg_show_total");
        var subTotal = $(window.parent.document).find("#msg_sub_total");
        var newCount = parseInt(total.text()) - 1;
        total.text(newCount);
        subTotal.text(newCount);
        var msg = $(window.parent.document).find("#msgId_" + msgId);
        msg.remove();
    });
</script>
</body>
